﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using RH.Common.Extensions;

namespace RH.Web.Utility
{
    public class ConfigReader
    {
        private static String GetAppSettingsValue(String key)
        {
            return ConfigurationManager.AppSettings[key];
        }        
        public static String SmtpHost
        {
            get
            {
                return GetAppSettingsValue("SmtpHost");
            }
        }
        /// <summary>
        /// Get the Configuration Value for SMTP port. If not specified then retuns a default value of 25
        /// </summary>
        public static int SmtpPort
        {
            get
            {
                int port = 0;
                String paramValue = GetAppSettingsValue("SmtpPort");
                int.TryParse(paramValue, out port);
                return port == 0 ? 25 : port;
            }
        }
        public static String SupportEmail
        {
            get
            {
                return GetAppSettingsValue("SupportEmail");
            }
        }
        public static String ErrorEmail
        {
            get
            {
                return GetAppSettingsValue("ErrorEmail");
            }
        }
        public static String AdminEmail
        {
            get
            {
                return GetAppSettingsValue("AdminEmail");
            }
        }
        public static String SiteName
        {
            get
            {
                return GetAppSettingsValue("SiteName");
            }
        }
        public static String JSCalendarDateFormat
        {
            get
            {
                return GetAppSettingsValue("JSCalendarDateFormat");
            }
        }
        public static String CSharpCalendarDateFormat
        {
            get
            {
                return GetAppSettingsValue("CSharpCalendarDateFormat");
            }
        }

        public static String LuceneSavedStateName
        {
            get
            {
                return GetAppSettingsValue("LuceneSavedStateName");
            }
        }
        public static String LuceneIndexDirectory
        {
            get
            {
                return GetAppSettingsValue("LuceneIndexDirectory");
            }
        }
        /// <summary>
        /// Gets or Sets the MaxNumber OfProductImages
        /// Default Value is 4 If noting is set in the Configuration
        /// </summary>
        public static int MaxNumberOfProductImages
        {
            get
            {
                int count = 0;
                String paramValue = GetAppSettingsValue("MaxNumberOfProductImages");
                count = paramValue.ToInt();
                return count <= 0 ? 4 : count; 
            }
        }
        //public static int MaxNumberLogo
        //{
        //    get
        //    {
        //        int count = 0;
        //        String paramValue = GetAppSettingsValue("MaxNumberLogo");
        //        count = paramValue.ToInt();
        //        return count <= 0 ? 1 : count;
        //    }
        //}
        public static int UserGroupIDOfSiteUser
        {
            get
            {
                String paramValue = GetAppSettingsValue("UserGroupIDOfSiteUser");
                return paramValue.ToInt();
            }
        }
        public static int UserGroupIDOfAdmin
        {
            get
            {
                String paramValue = GetAppSettingsValue("UserGroupIDOfAdmin");
                return paramValue.ToInt();
            }
        }
        public static int UserGroupIDOfCompanyAdmin
        {
            get
            {
                String paramValue = GetAppSettingsValue("UserGroupIDOfCompanyAdmin");
                return paramValue.ToInt();
            }
        }
        public static int UserGroupIDOfCompanyUser
        {
            get
            {
                String paramValue = GetAppSettingsValue("UserGroupIDOfCompanyUser");
                return paramValue.ToInt();
            }
        }
        public static String CurrencyCode
        {
            get
            {
                String paramValue = GetAppSettingsValue("CurrencyCode");
                if (paramValue.IsEmpty())
                    return "Tk";

                return paramValue;
            }
        }

        public static int AboutUs
        {
            get
            {
                String paramValue = GetAppSettingsValue("AboutUs");
                return paramValue.ToInt();
            }
        }

        public static int OurServices
        {
            get
            {
                String paramValue = GetAppSettingsValue("OurServices");
                return paramValue.ToInt();
            }
        }

        public static int FAQ
        {
            get
            {
                String paramValue = GetAppSettingsValue("FAQ");
                return paramValue.ToInt();
            }
        }

        public static int ContactUs
        {
            get
            {
                String paramValue = GetAppSettingsValue("ContactUs");
                return paramValue.ToInt();
            }
        }

        public static int pageSize
        {
            get
            {
                String paramValue = GetAppSettingsValue("pageSize");
                if (paramValue.ToInt() > 0)
                    return paramValue.ToInt();
                return 10;
            }
        }

        public static int SearchPageSize
        {
            get
            {
                String paramValue = GetAppSettingsValue("SearchPageSize");
                if (paramValue.ToInt() > 0)
                    return paramValue.ToInt();
                return 10;
            }
        }

        /// <summary>
        /// Determines How Many Products can be compared at a time.
        /// </summary>
        public static int MaxNoOfProductsCanBeCompare
        {
            get
            {
                String paramValue = GetAppSettingsValue("MaxNoOfProductsCanBeCompare");
                if (paramValue.ToInt() > 0)
                    return paramValue.ToInt();
                return 3;
            }
        }
        public static bool SendEmailThroughGmail
        {
            get
            {
                String paramValue = GetAppSettingsValue("SendEmailThroughGmail");
                if (String.Compare(paramValue, "True", true) == 0)
                    return true;
                return false;
            }
        }

        public static string CompaniesUrlConfigurationKey
        {
            get
            {
                return GetAppSettingsValue("CompaniesUrlConfigurationKey");
            }
        }
        public static string ContentsUrlConfigurationKey
        {
            get
            {
                return GetAppSettingsValue("ContentsUrlConfigurationKey");
            }
        }
        public static float CompanyLogoAspectRatio
        {
            get
            {
                String paramValue = GetAppSettingsValue("CompanyLogoAspectRatio");
                if (paramValue.ToFloat() > 0)
                    return paramValue.ToFloat();
                return (float) 3.175;
            }
        }
        public static float ProductImageAspectRatio
        {
            get
            {
                String paramValue = GetAppSettingsValue("ProductImageAspectRatio");
                if (paramValue.ToFloat() > 0)
                    return paramValue.ToFloat();
                return (float)1.333;
            }
        }

        public static int DefaultLocationID
        {
            get
            {
                return GetAppSettingsValue("DefaultLocationID").ToInt();
            }
        }

        public static int IndustryTypeID
        {
            get
            {
                return GetAppSettingsValue("IndustryTypeID").ToInt();
            }
        }

        public static int ReligionID
        {
            get
            {
                return GetAppSettingsValue("ReligionID").ToInt();
            }
        }
        public static String SmtpFromEmail
        {
            get
            {
                return GetAppSettingsValue("SmtpFromEmail");
            }
        }
        public static bool IsProductionDeployment
        {
            get
            {
                String paramValue = GetAppSettingsValue("IsProductionDeployment");
                return paramValue.ToBoolean();
            }
        }
        public static int NumberOfRowsInCategoryMenu
        {
            get
            {
                String paramValue = GetAppSettingsValue("NumberOfRowsInCategoryMenu");
                if (paramValue.ToInt() > 0)
                    return paramValue.ToInt();
                return 15;
            }
        }
        //public static int NumberOfRowsInCategorySelection
        //{
        //    get
        //    {
        //        String paramValue = GetAppSettingsValue("NumberOfRowsInCategorySelection");
        //        if (paramValue.ToInt() > 0)
        //            return paramValue.ToInt();
        //        return 15;
        //    }
        //}
        public static int ProductThumbWidth
        {
            get
            {
                String paramValue = GetAppSettingsValue("ProductThumbWidth");
                if (paramValue.ToInt() > 0)
                    return paramValue.ToInt();
                return 140;
            }
        }
        public static bool AutoApproveProduct
        {
            get
            {
                String paramValue = GetAppSettingsValue("AutoApproveProduct");
                return paramValue.ToBoolean();
            }
        }
        public static int ForceCountryID
        {
            get
            {
                String paramValue = GetAppSettingsValue("ForceCountryID");
                if (paramValue.ToInt() > 0)
                    return paramValue.ToInt();
                return 0;
            }
        }
        public static bool LogErrorsInDb
        {
            get
            {
                String paramValue = GetAppSettingsValue("LogErrorsInDb");
                if (paramValue.IsNullOrEmpty())
                    return true;
                
                return paramValue.ToBoolean();
            }
        }
        
    }
}